package net.lab1024.sa.admin.module.business.summary.service;

import java.util.List;
import net.lab1024.sa.admin.module.business.summary.dao.SummaryInfoDao;
import net.lab1024.sa.admin.module.business.summary.domain.entity.SummaryInfoEntity;
import net.lab1024.sa.admin.module.business.summary.domain.form.SummaryInfoAddForm;
import net.lab1024.sa.admin.module.business.summary.domain.form.SummaryInfoQueryForm;
import net.lab1024.sa.admin.module.business.summary.domain.form.SummaryInfoUpdateForm;
import net.lab1024.sa.admin.module.business.summary.domain.vo.SummaryInfoVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;

/**
 * 报价单汇总 - 一条对应多个报价单 Service
 *
 * @Author zzx
 * @Date 2025-08-30 15:49:03
 * @Copyright zzx
 */

@Service
public class SummaryInfoService {

    @Resource
    private SummaryInfoDao summaryInfoDao;

    /**
     * 分页查询
     */
    public PageResult<SummaryInfoVO> queryPage(SummaryInfoQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<SummaryInfoVO> list = summaryInfoDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(SummaryInfoAddForm addForm) {
        SummaryInfoEntity summaryInfoEntity = SmartBeanUtil.copy(addForm, SummaryInfoEntity.class);
        summaryInfoDao.insert(summaryInfoEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     */
    public ResponseDTO<String> update(SummaryInfoUpdateForm updateForm) {
        SummaryInfoEntity summaryInfoEntity = SmartBeanUtil.copy(updateForm, SummaryInfoEntity.class);
        summaryInfoDao.updateById(summaryInfoEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        summaryInfoDao.batchUpdateDeleted(idList, true);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Long summaryId) {
        if (null == summaryId){
            return ResponseDTO.ok();
        }

        summaryInfoDao.updateDeleted(summaryId, true);
        return ResponseDTO.ok();
    }
}
